

** create income dist variable for 2012 and 2016 
use "$dir/data/outputs/acs2012_2016adults.dta", replace


keep if hhincome !=. 
gen acs2012 = 1 if year==2012
gen acs2016 = 1 if year == 2016
collapse (percent) acs2012 acs2016 [fweight=perwt], by(incomecat)
sort incomecat
replace incomecat = _n
save "$dir/data/outputs/acs_incomecat", replace 

use "$dir/data/raw-data/ALP-HHbox-demographics", clear
keep if incomecat!=.
gen alp2013 = 1 
gen complete1_2013 = 1 if complete == 1
gen complete2_2013 = 1 if complete2 == 1
collapse (percent) alp2013 complete1_2013 complete2_2013 , by(incomecat) 
save "$dir/data/outputs/ALP2013_incomecat", replace 


use "$dir/data/raw-data/ALP-HHbox-demographics2016", clear
 drop _m
 merge m:1 prim_key using "$dir/data/raw-data/ALP2_primkeys.dta", keepusing(complete)
gen complete = _m==3
drop _m
gen alp2016 = 1 
gen complete1_2016 = 1 if complete == 1
gen complete2_2016 = 1 if complete2 == 1
keep if incomecat!=.
collapse (percent) alp2016 complete1_2016 complete2_2016 , by(incomecat) 
merge 1:1 incomecat using "$dir/data/outputs/acs_incomecat"
drop _m
merge 1:1 incomecat using "$dir/data/outputs/ALP2013_incomecat"
drop _m
  cap erase "$dir/data/outputs/ALP2013_incomecat"

eststo clear
eststo: estpost tabstat complete2_2013 complete2_2016 acs2012 acs2016, by(incomecat) stat(mean) columns(variables) nototal
esttab . using "$dir/tables-and-figures/table2.tex", replace fragment booktabs noobs wrap varwidth(20) alignment(ccccc)  cells("complete2_2013(fmt(a2)) complete2_2016(fmt(a2)) acs2012(fmt(a2)) acs2016(fmt(a2))") nonumber collabels(none) nomtitles
